package datasv.framework_datasv;

import resultmessage.FrameworkRM;
import data.datafactory.DatabaseOperator;

public class UpdateSubModelOfCou {
	public static void main(String[] args) {
		System.out.println(new UpdateSubModelOfCou().updateSubModelOfCou("00101130010", "001010201"));
	}
	public FrameworkRM updateSubModelOfCou(String courseID, String submodelID) {
		return updateInSql(courseID, submodelID);
	}

	private FrameworkRM updateInSql(String courseID, String submodelID) {
		DatabaseOperator op = new DatabaseOperator("college");
		if (!op.ifDatabaseExist()
				|| !op.ifFormExist("plan_submodel_list_"
						+ submodelID.substring(0, 7))) {
			return FrameworkRM.SUBMODELID_NOT_EXIST;
		}
		if (!op.ifIDExist("course_list", courseID)) {
			return FrameworkRM.COURSEID_NOT_EXIST;
		}
		if (op.getOneInform(courseID, "course_list", "submodelID") == null) {
			return FrameworkRM.COURSE_SUBMODEL_NOT_EXIST;
		}
		if (op.setOneInform(courseID, submodelID, "course_list", "submodelID")) {
			return FrameworkRM.SUCCESS;
		}
		return FrameworkRM.FAIL;
	}
}
